//
//  DetailViewController.m
//  Read
//
//  Created by lanou on 15/12/18.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "DetailViewController.h"
#import "DetailView.h"
#import "Novel.h"

@interface DetailViewController ()

@property (nonatomic, strong) NSMutableArray *array;
@property (nonatomic, strong) DetailView *novelView;

@end

@implementation DetailViewController


- (void)jsonBook {
    
    //从上个页面传过来一个gid
    [LORequestManger GET:@"http://api.easou.com/api/bookapp/cover.m?gid=3481724&cid=eef_easou_book" success:^(id response) {
        
        NSDictionary *dic = (NSDictionary *)response;
        _array = [NSMutableArray array];

        Novel *novel = [Novel jsonWithDictionary:dic];
        
        [_array addObject:novel];
        
        _novelView = [[DetailView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [_novelView putValueWithModel:novel];
        self.view= _novelView;
        NSLog(@"%@", _array);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self jsonBook];
    CGFloat tempHeight = [self heightForString:self.novelView.descLabel.text];
     self.novelView.descLabel.frame= CGRectMake(CGRectGetMinX(self.novelView.nameLabel.frame), CGRectGetMaxY(self.novelView.nameLabel.frame)+5, CGRectGetWidth(self.novelView.frame)-40, tempHeight+40);
    self.novelView.backScrollView.contentSize = CGSizeMake(CGRectGetWidth(self.novelView.frame) -10, tempHeight+300);
    // Do any additional setup after loading the view.
}

- (CGFloat)heightForString:(NSString *)string {
    
    NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};// 一定要大于等于实际的字体
    
    //将传进来的字符串放在一个矩形中
    CGRect rect = [string boundingRectWithSize:CGSizeMake(CGRectGetWidth(self.novelView.backScrollView.frame)-20, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    return rect.size.height;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
